---
title: "Replication of the Analyses for 'Threats and Commitments: International Tribunals and Domestic Trials in Peace Negotiations'"
author: "Genevieve Bates"
date: "09/2025"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE,
                      warning = FALSE,
                      results = 'asis')

# Cleaning the working memory:
rm(list=ls(all=TRUE))

#Set working directory
setwd("~/Replication")

library(dplyr)
library(tidyverse)
library(readr)
library(readxl)
library(haven)
library(zoo)
library(date)
library(glm2)
library(ggplot2)
library(brglm2)
library(brglm)
library(xtable)
library(modelsummary)
```

#Data
```{r data, include=FALSE}
load("Data/Analysis/AnalysisData.RData")

#this is just cleaning the data we will use for the primary analysis
data2 <- data%>%
  filter(year>=2002)%>%
  filter(!is.na(lag_loggdppc),!is.na(ICC_ratification),!is.na(ic_UNOth),!is.na(v2x_partipdem),!is.na(v2xcl_acjst),!is.na(hrfilled),!is.na(time),!is.na(lag_casualties),!is.na(log_atrpost2002),!is.na(UcdpCon),!is.na(lag_odagni))
```

#Main Text
##Figures
```{r Code Used to Produce Figure 1, echo=FALSE}
#This code produces Figure 1 on page 16 of the main text

#For this I'll need the panel data, so I load that in
load("Data/Analysis/PanelData.RData")

ICC <- df3%>%
#First, I filter the data to include only the countries with agreements in the PAX data
  filter(agmt==1)%>%
  #Now I make character vector that tracks the level of ICC involvement using text rather than numbers
  mutate(level = case_when(extent==0 ~ "None",
                           extent ==1 ~ "Preliminary Examination",
                           extent ==2 ~ "Formal Investigation",
                           extent == 3 ~ "Arrest Warrant",
                           extent == 4 ~ "Trial",
                           extent == 5 ~ "Conviction"))

#Now I set the factor order for each level of involvement so that the figure actually puts each stage in the correct order
ICC$level <- factor(ICC$level, 
                             levels = c("None", "Preliminary Examination", "Formal Investigation", "Arrest Warrant", "Trial","Conviction"))

#I do the same thing for country names because I want them to be in alphabetical order in the figure
ICC$country <- factor(ICC$country, levels = rev(sort(unique(ICC$country))))
#And just in case I do it for year so that everything is in the correct order
ICC$year <- factor(ICC$year)

#Now this is the ggplot that actually produces Figure 1
panel<- ggplot(ICC, aes(x = year, y = country, group = country, color = level)) +
  geom_line(aes(group = country), size = 5) +
  scale_color_grey(name = waiver(),
  start = 0.9,
  end = 0.2,
  na.value = "red",
  aesthetics = "colour") +
  theme_minimal(
    base_size = 15) +
  theme(
    panel.grid = element_blank())+
  labs(x = "Year",
       y = "Country",
       color = "Stage of Involvement") 

ggsave("Results/Figure1.pdf", width=14, height=8)

remove(ICC,df3,panel)
```

##Tables
```{r Models, echo=FALSE}
#Base
threatibase <- glm(natcourts2 ~ threati + intervention, family = binomial(logit), data=data2, method = "brglmFit")

#Base + Alternative
threatialt <- glm(natcourts2 ~ threati + intervention + hrfilled + ICC_ratification + lag_casualties + log_atrpost2002  + ic_UNOth+ lag_odagni, family = binomial(logit), data=data2, method = "brglmFit")

#Full Specifications
threatifull <- glm(natcourts2 ~ threati + intervention + hrfilled + ICC_ratification + lag_casualties + log_atrpost2002  + ic_UNOth+ lag_odagni + v2x_partipdem + v2xcl_acjst + lag_loggdppc + Africa + time, family = binomial(logit), data=data2, method = "brglmFit")
```

```{r Code Used to Produce Table 1}
options("modelsummary_format_numeric_latex" = "plain")
#INSTITUTIONAL MEASURE
msummary(list(threatibase, threatialt, threatifull),
         vcov = ~ country,
         coef_rename = c("threati" = "Threat", "intervention" = "Intervention","hrfilled" =  "HR Organizations", "ICC_ratification" = "Rome Statute Ratification", "lag_casualties"= "Combatant Casualties (lag)", "log_atrpost2002" = "Atrocities","ic_UNOth" = "IO Signature","lag_odagni" = "Foreign Aid (lag)", "v2x_partipdem" =  "Participatory Democracy", "v2xcl_acjst" =  "Access to Justice", "lag_loggdppc" = "GDP Per Capita (lag)", "Africa" = "Africa","time"="Time"),
         coef_omit = "Intercept",
         gof_omit = 'AIC|BIC|RMSE',
         stars = c('*' = .1, '**' = .05, '***' = .01),
          estimate = "{estimate}{stars}", 
         statistic = c("[{conf.low}, {conf.high}]",
                       "({p.value})"),
         notes = list('*p<.10, **p<.05, ***p<.01.'),
        output = "Results/Table1.tex",
          title = "ICC Involvement and Domestic Trial Commitments in Peace Agreements")
```

#Appendices
##Appendix A - Summary Stats and Figures
```{r Code Used to Produce Figure A1, echo=FALSE}
#This code produces Figure A1 on page 1 of the online appendices

#first, I create a data frame that includes a character vector of whether the agreement included a trial commitment, another TJ commitment, or none of the above
agreement <- data2%>%
  mutate(agreement = 1,
         allcontent = ifelse(tj==1,"Other TJ","No TJ"),
         allcontent = ifelse(natcourts2==1,"Trial",allcontent))%>%
  select(allcontent,year,agreement)

#this produces the actual figure
proportion_all <- ggplot(data=agreement, aes(x = year, y = agreement, fill = allcontent)) +
  geom_col(position = "fill") + theme_classic() + scale_fill_discrete(name="Content of Agreement",
                         breaks=c("No TJ", "Other TJ", "Trial"),
                         labels=c("No TJ Commitment", "Other TJ Commitment", "Domestic Trial Commitment")) + labs(x="Year", y = "Proportion of All Agreements")

ggsave("Results/FigureA1.pdf", width=6.5, height=3)

remove(agreement, proportion_all)
```

```{r Code Used to Produce Table A1, echo=FALSE}
#making a dataframe of only the data necessary for the summary stats table. I will have to manually adjust the names and remove irrelevant summary stats
data3 <- data2%>%
  dplyr::select(natcourts2,threati,intervention,ic_UNOth,ICC_ratification,v2x_partipdem,v2xcl_acjst,hrfilled,lag_loggdppc,lag_odagni,lag_casualties,log_atrpost2002,natcourts,natcourts3,unscref,art14ref,propmo)

#This produces Table A1 on page 1 of the online appendices
datasummary_skim(data3,
                 fmt = 3,
                 output = 'Results/TableA1.tex')

#now removing this dataframe
remove(data3)
```

##Appendix B - Robustness Checks and Alternate Specifications
###B.1 - Bootstrapping Standard Errors
```{r Code Used to Produce Table B1, echo=FALSE}
#This produces Table B1 on page 2 of the online appendices. The estimated run time for this is about 5 minutes because of the bootstrapping processing time
set.seed(1)
options("modelsummary_format_numeric_latex" = "plain")
#INSTITUTIONAL MEASURE
msummary(list(threatibase, threatialt, threatifull),
          vcov = "bootstrap", R = 1000, cluster = ~country, type="fractional",
         coef_rename = c("threati" = "Threat", "intervention" = "Intervention","hrfilled" =  "HR Organizations", "ICC_ratification" = "Rome Statute Ratification", "lag_casualties"= "Combatant Casualties (lag)", "log_atrpost2002" = "Atrocities","ic_UNOth" = "IO Signature","lag_odagni" = "Foreign Aid (lag)", "v2x_partipdem" =  "Participatory Democracy", "v2xcl_acjst" =  "Access to Justice", "lag_loggdppc" = "GDP Per Capita (lag)", "Africa" = "Africa","time"="Time"),
         coef_omit = "Intercept",
         gof_omit = 'AIC|BIC|RMSE',
         stars = c('*' = .1, '**' = .05, '***' = .01),
          estimate = "{estimate}{stars}", 
         statistic = c("[{conf.low}, {conf.high}]",
                       "({p.value})"),
         notes = list('*p<.10, **p<.05, ***p<.01.'),
        output = "Results/TableB1.tex",
          title = "Relationship Between ICC Involvement and Domestic Trial Commitments (Bootstrapped SEs)")

#removing all but the main the model from this section
remove(threatibase,threatialt)
```

###B.2 - Accounting for Referral Mechanism
```{r Models, echo=FALSE}
##REFERRAL MECHANISM
#Base
refmechbase <- glm(natcourts2 ~ unscref + art14ref + propmo, family = binomial(logit), data=data2, method = "brglmFit")

#Base + Alternative
refmechalt <- glm(natcourts2 ~ unscref + art14ref + propmo + hrfilled + ICC_ratification + lag_casualties + log_atrpost2002  + ic_UNOth+ lag_odagni, family = binomial(logit), data=data2, method = "brglmFit")

#Full Specification
refmechfull <- glm(natcourts2 ~ unscref + art14ref + propmo + hrfilled + ICC_ratification + lag_casualties + log_atrpost2002  + ic_UNOth+ lag_odagni + v2x_partipdem + v2xcl_acjst + lag_loggdppc + Africa + time, family = binomial(logit), data=data2, method = "brglmFit")
```

```{r Code Used to Produce Table B2, echo=FALSE}
#This produces Table B2 on page 3 of the online appendices 
msummary(list(refmechbase,refmechalt,refmechfull),
        vcov = ~ country,
         coef_rename = c("unscref" = "UNSC Referral", "art14ref" = "Article 14 Referral", "propmo" = "Propio Motu Referral","hrfilled" =  "HR Organizations", "ICC_ratification" = "Rome Statute Ratification", "lag_casualties"= "Combatant Casualties (lag)", "log_atrpost2002" = "Atrocities","ic_UNOth" = "IO Signature","lag_odagni" = "Foreign Aid (lag)", "v2x_partipdem" =  "Participatory Democracy", "v2xcl_acjst" =  "Access to Justice", "lag_loggdppc" = "GDP Per Capita (lag)", "Africa" = "Africa","time"="Time"),
         coef_omit = "Intercept",
        gof_omit = 'AIC|BIC|RMSE',
         stars = c('*' = .1, '**' = .05, '***' = .01),
          estimate = "{estimate}{stars}", 
         statistic = c("[{conf.low}, {conf.high}]",
                       "({p.value})"),
        output = "Results/TableB2.tex",
          title = "ICC Involvement by Referral Mechanism and Domestic Trial Commitments in Peace Agreements")

#removing the models from this section
remove(refmechbase,refmechalt,refmechfull)
```

###B.3 - ICC Involvement by Stage
```{r Models, echo=FALSE}
#For completeness, I estimate the base models and the models accounting for alternative explanations, but I only include the full models in the final tables
stagebase <- glm(natcourts2 ~ stage, family = binomial(logit), data=data2, method = "brglmFit")

stagealt <-  glm(natcourts2 ~ stage+ hrfilled + ICC_ratification + lag_casualties + log_atrpost2002  + ic_UNOth+ lag_odagni, family = binomial(logit), data=data2, method = "brglmFit")

stagefull<- glm(natcourts2 ~ stage + hrfilled + ICC_ratification + lag_casualties + log_atrpost2002  + ic_UNOth+ lag_odagni + v2x_partipdem + v2xcl_acjst + lag_loggdppc + Africa + time, family = binomial(logit), data=data2, method = "brglmFit")

##Assuming non-linearity - accounting for the extent of involvement. Again, for completeness, I estimate the base models and the models accounting for alternative explanations, but I only include the full models in the final tables
extentbase <- glm(natcourts2 ~ extent^2, family = binomial(logit), data = data2, method = "brglmFit" )

extentalt <-  glm(natcourts2 ~ extent^2+ hrfilled + ICC_ratification + lag_casualties + log_atrpost2002  + ic_UNOth+ lag_odagni, family = binomial(logit), data=data2, method = "brglmFit")

extentfull<- glm(natcourts2 ~ extent^2 + hrfilled + ICC_ratification + lag_casualties + log_atrpost2002  + ic_UNOth+ lag_odagni + v2x_partipdem + v2xcl_acjst + lag_loggdppc + Africa + time, family = binomial(logit), data=data2, method = "brglmFit")
```

```{r Code Used to Produce Table B3, echo=FALSE}
#This produces Table B3 on page 5 of the online appendices
msummary(list(stagefull,extentfull),
         vcov = ~ country,
         coef_rename = c("stageconviction" = "Conviction", "stageformal" = "Formal Investigation", "stageprelim" = "Preliminary Examination", "stagetrial" = "Trial", "stagewarrant" = "Arrest Warrant", "extent" = "Stage^2", "hrfilled" =  "HR Organizations", "ICC_ratification" = "Rome Statute Ratification", "lag_casualties"= "Combatant Casualties (lag)", "log_atrpost2002" = "Atrocities","ic_UNOth" = "IO Signature","lag_odagni" = "Foreign Aid (lag)", "v2x_partipdem" =  "Participatory Democracy", "v2xcl_acjst" =  "Access to Justice", "lag_loggdppc" = "GDP Per Capita (lag)", "Africa" = "Africa","time"="Time"),
         coef_omit = "Intercept",
         gof_omit = 'AIC|BIC|RMSE',
         stars = c('*' = .1, '**' = .05, '***' = .01),
          estimate = "{estimate}{stars}", 
         statistic = c("[{conf.low}, {conf.high}]",
                       "({p.value})"),
        output = "Results/TableB3.tex",
          title = "ICC Involvement (by Stage of Involvement) and Domestic Trial Commitments in Peace Agreements")

#removing the models from this section
remove(stagebase,stagealt,stagefull,extentbase,extentalt,extentfull)
```

###B.4 - Lagged Models
```{r Models, echo=FALSE}
#Here I lag the primary explanatory variables
threatilag <- glm(natcourts2 ~ threatilag + interventionlag +  hrfilled + ICC_ratification + lag_casualties + log_atrpost2002  + ic_UNOth+ lag_odagni + v2x_partipdem + v2xcl_acjst + lag_loggdppc + Africa + time, family = binomial(logit), data=data2, method = "brglmFit")

#And here I estimate a model with all of the non-agreement-level variables lagged
alllag <- glm(natcourts2 ~ threatilag + interventionlag + lag_hrfilled +lag_ICCrat + lag_casualties + lag_atrpost2002 + ic_UNOth + lag_odagni+ lag_partipdem + lag_acjst+lag_loggdppc+ Africa + time, family = binomial(logit), data=data2, method = "brglmFit")
```

```{r Code Used to Produce Tables B4 and B5, echo=FALSE}
#This produces Table B4 on page 6 of the online appendices
msummary(threatilag,
         vcov = ~ country,
         coef_rename = c("threatilag" = "Threat (lag)", "interventionlag" = "Intervention (lag)", "hrfilled" =  "HR Organizations", "ICC_ratification" = "Rome Statute Ratification", "lag_casualties"= "Combatant Casualties (lag)", "log_atrpost2002" = "Atrocities","ic_UNOth" = "IO Signature","lag_odagni" = "Foreign Aid (lag)", "v2x_partipdem" =  "Participatory Democracy", "v2xcl_acjst" =  "Access to Justice", "lag_loggdppc" = "GDP Per Capita (lag)", "Africa" = "Africa","time"="Time"),
         coef_omit = "Intercept",
         gof_omit = 'AIC|BIC|RMSE',
         stars = c('*' = .1, '**' = .05, '***' = .01),
          estimate = "{estimate}{stars}", 
         statistic = c("[{conf.low}, {conf.high}]",
                       "({p.value})"),
         notes = list('*p<.10, **p<.05, ***p<.01.'), 
        output = "Results/TableB4.tex",
          title = "ICC Involvement (Lagged) and Domestic Trial Commitments in Peace Agreements")

#This produces Table B5 on page 7 of the online appendices
msummary(alllag,
         vcov = ~ country,
         coef_rename = c("threatilag" = "Threat (lag)", "interventionlag" = "Intervention (lag)", "lag_hrfilled" =  "HR Organizations (lag) ","lag_ICCrat" = "Rome Statute Ratification (lag)","lag_casualties"= "Combatant Casualties (lag)", "lag_atrpost2002" = "Atrocities (lag)","ic_UNOth" = "IO Signature","lag_odagni" = "Foreign Aid (lag)","lag_partipdem" =  "Participatory Democracy (lag)", "lag_acjst" =  "Access to Justice (lag)","lag_loggdppc" = "GDP Per Capita (lag)", "Africa" = "Africa","time"="Time"),
          coef_omit = "Intercept",
         gof_omit = 'AIC|BIC|RMSE',
         stars = c('*' = .1, '**' = .05, '***' = .01),
          estimate = "{estimate}{stars}", 
         statistic = c("[{conf.low}, {conf.high}]",
                       "({p.value})"),
        output = "Results/TableB5.tex",
          title = "ICC Involvement and Domestic Trial Commitments in Peace Agreements (Lagged Model)")

#removing the models from this section
remove(threatilag,alllag)

```

###B.5 - Sensitivity Analyses
```{r Code Used to Produce Figures B1(a) and B1(b), echo=FALSE}
#NOTE: The run time for this code is approximately 14 minutes

#There are 35 agreements with a trial commitment, so I create a dataframe to account for this
thresholds <- seq(1, 35, 1)

#create df that includes a variable with a running count of the 35 agreements with trial commitments
 dvcheck <- data2%>%
  mutate(ntct2 = cumsum(natcourts2),
         ntct = ifelse(natcourts2==1,ntct2,0))%>%
  dplyr::select(-ntct2)

# Create dataframe to populate with results
drop_one_df <- data.frame()
# Loop over thresholds running model
for(i in 1:length(thresholds)){
  #create df that drops one observation at a time using the 35 agreements with trial commitments as the index
  data_subset <- filter(dvcheck, !ntct==i)
  # Run model
  mod_brglm <- brglm(natcourts2 ~ threati+intervention + lag_loggdppc + lag_odagni + ICC_ratification + ic_UNOth + v2x_partipdem + v2xcl_acjst + hrfilled + lag_casualties + log_atrpost2002 + Africa + time, family = binomial(logit), data=data_subset, method = "brglm.fit")
  
  coef_ci <- data.frame(coefficients = coef(mod_brglm)[2:3], confint(mod_brglm)[2:3, ])
  coef_ci$threshold <- i
  
  drop_one_df <- rbind(drop_one_df, coef_ci)
}

df <- drop_one_df
df$variable <- row.names(drop_one_df)
df<- df%>%
  mutate(conf.low = X2.5..,
         conf.high = X97.5..,
         v1 = ifelse(grepl("intervention", variable), "intervention", "threati"))%>%
  select(-X2.5..,-X97.5..,-variable)

df2<- df%>%filter(v1=="intervention")%>%
  rename(coef = coefficients)%>%
  select(-v1)
  
df3 <- df%>%filter(v1=="threati")%>%
  rename(coef2 = coefficients,
         conf.low2 = conf.low,
         conf.high2 = conf.high)%>%
  select(-v1)

dvbrglm <- df2%>%left_join(df3)
  

#merging into the results dataframe the agreement IDs for each observation dropped over the loop
dvbrglm2 <- dvcheck%>%filter(ntct>0)%>%select(ntct,AgtId)%>%mutate(threshold=ntct)
dvbrglm <- dvbrglm%>%left_join(dvbrglm2)%>%select(-ntct)


# Coefficient plot for results dropping each observation where my DV==1, note that the x-axis matches the agreement ID for the dropped observation to the results
#This produces the plot included as Figure B1(b) on page 8 of the online appendices
dvbrglmfig <- dvbrglm %>%
  ggplot() + geom_point(aes(x = as.factor(AgtId), y = coef)) + geom_linerange(aes(x = threshold, ymin = conf.low, ymax = conf.high)) +
  geom_hline(yintercept = 0, lty = 3) +
  labs(x = "ID Number of Agreement Dropped", y = "Probability of Domestic Trial Commitment", title = " ") + theme_minimal() +
  theme(legend.position = "none") + theme(axis.text.x = element_text(angle = 65, hjust = 1))
ggsave("Results/FigureB1b.pdf", width=6, height=4)


#This produces the plot included as Figure B1(a) on page 8 of the online appendices
dvbrglmfig2 <- dvbrglm %>%
  ggplot() + geom_point(aes(x = as.factor(AgtId), y = coef2)) + geom_linerange(aes(x = threshold, ymin = conf.low2, ymax = conf.high2)) +
  geom_hline(yintercept = 0, lty = 3) +
  labs(x = "ID Number of Agreement Dropped", y = "Probability of Domestic Trial Commitment", title = " ") + theme_minimal() +
  theme(legend.position = "none") + theme(axis.text.x = element_text(angle = 65, hjust = 1))
ggsave("Results/FigureB1a.pdf", width=6, height=4)

#removing all of the dataframes and models from this section
remove(thresholds,dvcheck,drop_one_df,coef_ci,df,df2,df3,dvbrglm,dvbrglm2,dvbrglmfig,dvbrglmfig2,data_subset,mod_brglm,i)
```


```{r Code Used to Produce Figures B2(a) and B2(b), echo=FALSE}
#NOTE: The run time for this code is approximately 23 minutes

#There are 43 countries with agreements in the data, so I create a dataframe to account for this
thresholds2 <- seq(1, 43, 1)

#create df that includes a variable with a running count of the 43 countries with agreements
ctycheck <- data2%>%
  group_by(country) %>%
  mutate(gnumber = cur_group_id())
  
# Create dataframe to populate with results
ctybrglm <- data.frame()
# Loop over thresholds running model
for(i in 1:length(thresholds2)){
   #create df that drops all observations for a given country at a time using the 43 countries as the index
  data_subset2 <- filter(ctycheck, !gnumber==i)
  # Run model
  mod2_brglm <- brglm(natcourts2 ~ threati+intervention + lag_loggdppc + lag_odagni + ICC_ratification + ic_UNOth + v2x_partipdem + v2xcl_acjst + hrfilled + lag_casualties + log_atrpost2002 + Africa + time, family = binomial(logit), data=data_subset2, method="brglm.fit")
  
   coef_ci2 <- data.frame(coefficients = coef(mod2_brglm)[2:3], confint(mod2_brglm)[2:3, ])
  coef_ci2$threshold <- i
  # Save coefficient and standard error
 ctybrglm <- rbind(ctybrglm, coef_ci2)
}

ctydf <- ctybrglm
ctydf$variable <- row.names(ctybrglm)
ctydf<- ctydf%>%
  mutate(conf.low = X2.5..,
         conf.high = X97.5..,
         v1 = ifelse(grepl("intervention", variable), "intervention", "threati"))%>%
  select(-X2.5..,-X97.5..,-variable)

ctydf2<- ctydf%>%filter(v1=="intervention")%>%
  rename(coef = coefficients)%>%
  select(-v1)
  
ctydf3 <- ctydf%>%filter(v1=="threati")%>%
  rename(coef2 = coefficients,
         conf.low2 = conf.low,
         conf.high2 = conf.high)%>%
  select(-v1)

ctybrglm <- ctydf2%>%left_join(ctydf3)
#merging into the results dataframe the country names for each set of observations dropped over the loop
out <- ctycheck%>%select(gnumber,country)%>%mutate(threshold=gnumber)
out2 <- out[!duplicated(out$threshold), ]
ctybrglm <- ctybrglm%>%left_join(out2)%>%select(-gnumber)

# Coefficient plot for results dropping all observations for one country at a time, note that the x-axis matches the country name for the dropped observations to the results 
#This produces the plot included as Figure B2(b) on page 10 of the online appendices
ctybrglmfig <- ctybrglm %>%
  ggplot() + geom_point(aes(x = as.factor(country), y = coef)) + geom_linerange(aes(x = threshold, ymin = conf.low, ymax = conf.high)) +
  geom_hline(yintercept = 0, lty = 3) +
  labs(x = "Country Dropped", y = "Probability of Domestic Trial Commitment", title = " ") + theme_minimal() +
  theme(legend.position = "none") + theme(axis.text.x = element_text(angle = 65, hjust = 1))
ggsave("Results/FigureB2b.pdf", width=6, height=5)


#This produces the plot included as Figure B2(a) on page 10 of the online appendices
ctybrglmfig2 <- ctybrglm %>%
  ggplot() + geom_point(aes(x = as.factor(country), y = coef2)) + geom_linerange(aes(x = threshold, ymin = conf.low2, ymax = conf.high2)) +
  geom_hline(yintercept = 0, lty = 3) +
  labs(x = "Country Dropped", y = "Probability of Domestic Trial Commitment", title = " ") + theme_minimal() + theme(legend.position = "none") + theme(axis.text.x = element_text(angle = 65, hjust = 1))
ggsave("Results/FigureB2a.pdf", width=6, height=5)

#removing all of the dataframes and models from this section
remove(thresholds2,ctycheck,ctydf,ctydf2,ctydf3,ctybrglm,out,out2,ctybrglmfig,ctybrglmfig2,coef_ci2,data_subset2,mod2_brglm,i)
```

###B.6 - Alternative Measures of Trial Commitments
```{r Models, echo=FALSE}
#ALTERNATIVE DV -- NATCOURTS
ntc <- glm(natcourts ~ threati + intervention + hrfilled + ICC_ratification + lag_casualties + log_atrpost2002  + ic_UNOth+ lag_odagni + v2x_partipdem + v2xcl_acjst + lag_loggdppc + Africa + time, family = binomial(logit), data=data2, method = "brglmFit")

##ALTERNATIVE DV -- NATCOURTS 3
ntc2 <- glm(natcourts3 ~ threati + intervention + hrfilled + ICC_ratification + lag_casualties + log_atrpost2002  + ic_UNOth+ lag_odagni + v2x_partipdem + v2xcl_acjst + lag_loggdppc + Africa + time, family = binomial(logit), data=data2, method = "brglmFit")

```

```{r Code Used to Produce Table B6, echo=FALSE}
#This produces Table B6 on page 11 of the online appendices
msummary(list(threatifull, ntc, ntc2),
         vcov = ~ country,
         coef_rename = c("threati" = "Threat", "intervention" = "Intervention","hrfilled" =  "HR Organizations", "ICC_ratification" = "Rome Statute Ratification", "lag_casualties"= "Combatant Casualties (lag)", "log_atrpost2002" = "Atrocities","ic_UNOth" = "IO Signature","lag_odagni" = "Foreign Aid (lag)", "v2x_partipdem" =  "Participatory Democracy", "v2xcl_acjst" =  "Access to Justice", "lag_loggdppc" = "GDP Per Capita (lag)", "Africa" = "Africa","time"="Time"),
         coef_omit = "Intercept",
         gof_omit = 'AIC|BIC|RMSE',
         stars = c('*' = .1, '**' = .05, '***' = .01),
          estimate = "{estimate}{stars}", 
         statistic = c("[{conf.low}, {conf.high}]",
                       "({p.value})"),
         notes = list('*p<.10, **p<.05, ***p<.01.'),
        output = "Results/TableB6.tex",
          title = "ICC Involvement and Domestic Trial Commitments in Peace Agreements - Alternative DVs")

#removing everything but the full specification of the main model
remove(ntc,ntc2)
```

## Appendix C - The ICC as an Abstract Threat
```{r Models, echo=FALSE}
#This estimates the same models using the minimalist measure of threat
threatmbase <- glm(natcourts2 ~ threatm + intervention, family = binomial(logit), data=data2, method = "brglmFit")

threatmalt <- glm(natcourts2 ~ threatm + intervention + hrfilled + ICC_ratification + lag_casualties + log_atrpost2002  + ic_UNOth+ lag_odagni, family = binomial(logit), data=data2, method = "brglmFit")

threatmfull <- glm(natcourts2 ~ threatm + intervention + hrfilled + ICC_ratification + lag_casualties + log_atrpost2002  + ic_UNOth+ lag_odagni + v2x_partipdem + v2xcl_acjst + lag_loggdppc + Africa + time, family = binomial(logit), data=data2, method = "brglmFit")
```

```{r Code Used to Produce Table C1, echo=FALSE}
#This produces Table C1 on page 14 of the online appendices
msummary(list(threatmbase,threatmalt,threatmfull),
          vcov = ~ country,
         coef_rename = c("threatm" = "Threat", "intervention" = "Intervention", "hrfilled" =  "HR Organizations", "ICC_ratification" = "Rome Statute Ratification", "lag_casualties"= "Combatant Casualties (lag)", "log_atrpost2002" = "Atrocities","ic_UNOth" = "IO Signature","lag_odagni" = "Foreign Aid (lag)", "v2x_partipdem" =  "Participatory Democracy", "v2xcl_acjst" =  "Access to Justice", "lag_loggdppc" = "GDP Per Capita (lag)", "Africa" = "Africa","time"="Time"),
         coef_omit = "Intercept",
         gof_omit = 'AIC|BIC|RMSE',
         stars = c('*' = .1, '**' = .05, '***' = .01),
          estimate = "{estimate}{stars}", 
         statistic = c("[{conf.low}, {conf.high}]",
                       "({p.value})"),
         notes = list('*p<.10, **p<.05, ***p<.01.'),
        output = "Results/TableC1.tex",
          title = "ICC Involvement and Domestic Trial Commitments in Peace Agreements (Minimalist Measure)")

#removing the models from this section
remove(threatmbase,threatmalt,threatmfull,threatifull)
```

```{r Code Used to Produce Table C2, echo=FALSE}
#First I split the data into pre and post 2002 (when the Rome Statute went into effect)
df <- data%>%
  dplyr::select(natcourts2,year)%>%
  filter(year>=2002)%>%
  mutate(n = 1)
  
df2<-data%>%
  dplyr::select(natcourts2,year)%>%
  filter(year<2002)%>%
  mutate(n = 1)

#Now just for ease of presentation I'm creating a dataframe that number of agreements in each era, as well as the number of agreements with trial commitments in each era, and then the mean of trial commitments for each era
df3 <- data.frame(era=c("Pre-ICC","ICC"),
                 AgmtTotal=c(sum(df2$n),sum(df$n)),
                 natcourtsTotal=c(sum(df2$natcourts2),sum(df$natcourts2)),
                 mean = c(mean(df2$natcourts2),mean(df$natcourts2)))

#This produces Table C2 on page 15 of the online appendices. I will have to manually adjust some of the table headings
print.xtable(xtable(head(df3)), file = "Results/TableC2.tex")

#now I run a proportion test
pt<- prop.test(x = df3$natcourtsTotal, n = df3$AgmtTotal, alternative = "less")
print(pt)

remove(df,df2,df3)
```


